import './assets/main.css'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import { createApp, nextTick } from 'vue'
import App from './App.vue'

import router from './router/index'
import {pinia}  from '@glz/utils'

import { useQianKun } from './appRegister'

createApp(App)
.use(router)
.use(pinia)
.use(ElementPlus)
.mount('#app')

// error: QiankunError2: application 'sub-vite-ts' died in status LOADING_SOURCE_CODE: [qiankun]: Target container with #subapp-container not existed while sub-vite-ts loading!
// 子應用正在掛載（mount）時，主應用中指定的 container 容器不存在於 DOM 中
// 等到 #subapp-container 出現後再執行 qiankun
nextTick(() => {
    const checkContainer = () => {
      if (document.querySelector('#subapp-container')) {
        useQianKun()
      } else {
        // 等 100ms 再重試
        setTimeout(checkContainer, 100)
      }
    }
  
    checkContainer()
  })

